<?php
    require_once './handler/check_session.php';
    require_once './data/Dossier.php';
    require_once './data/Comptabilite.php';
    require_once './data/Banque.php';
    $dossier = null;
    $compta = null;
    $banque = null;
    $readOnlyMode = 'readonly="readonly"';
    $selectedItem = "selected='selected'";
    if($_SESSION['user'] != null && isset($_GET['id'])){
    	$dossier = Dossier::getDossierById($_GET['id']);
    	$compta = Comptabilite::getListComptaByDossier($_GET['id']);
    	$_SESSION['dossier'] = serialize($dossier);
    	if($_SESSION['user'] == 'admin' || $dossier->__get('statut') == 0){
    		$readOnlyMode = null;
    	}
    	$banque = Banque::getBanqueById($dossier->id_banque);
    }
    
    if($dossier != null){
    	$statut = 0;
    	switch ($dossier->__get('statut')) {
    		case 0:
    			$statut = 0;
    			break;
    		case 1:
    			$statut = 1;
    			break;
    		case 2:
    			$statut = 2;
    			break;
    		case 3:
    			$statut = 3;
    			break;
    		case 4:
    			$statut = 4;
    			break;
    		case 5:
    			$statut = 5;
    			break;
    		case 6:
    			$statut = 6;
    			break;
    		case 7:
    			$statut = 7;
    			break;
        }
        
        list($adresse1, $adresse2, $adresse3, $adresse4) = explode(ConfigClement::$separator_address, $dossier->adresse);
    }
    
    
    
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
    <head>
        <title>Edition Dossier</title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
        <link rel="STYLESHEET" type="text/css" href="style/header_footer_style.css" />
        <link rel="STYLESHEET" type="text/css" href="style/dossier_style.css" />
        <link rel="STYLESHEET" type="text/css" href="style/calendar_style.css" />
        <script type="text/javascript" src="scripts/datepickr.js"></script>
        <script type="text/javascript" src="scripts/checkApi.js"></script>
        <script type='text/javascript' src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
        <script type="text/javascript">
	        function manageCouverture() {
	        	var chomageBox = document.getElementById("chomage");
	        	var decesBox = document.getElementById("deces");
	        	var ptiaBox = document.getElementById("PTIA");
	        	var ittBox = document.getElementById("ITT");
	        	if(chomageBox.checked){
	        		decesBox.checked = "";
	        		decesBox.disabled = "true";
	        		ptiaBox.checked = "";
	        		ptiaBox.disabled = "true";
	        		ittBox.checked = "";
	        		ittBox.disabled = "true";
	        	} else {
	        		decesBox.checked = "checked";
	        		decesBox.disabled = "";
	        		ptiaBox.disabled = "";
	        		ittBox.disabled = "";
	        		chomageBox.checked = "";
	        		chomageBox.disabled = "true";
	        	}
	        }
	        			
	        function changeStatut(newStatut){
	        	for(var val = 0; val < 8; val++){
	        		if(val == newStatut){
	        			if(val >= 6){
	        				document.getElementById("statut"+val).style.backgroundImage="url(ressources/statut_current_resiliation.png)";
	        			}else{
	        				document.getElementById("statut"+val).style.backgroundImage="url(ressources/statut_current.png)";
	        				}
	        		}else {
	        			document.getElementById("statut"+val).style.backgroundImage="url(ressources/statut.png)";	
	        		}
	
	        	}
	        	document.getElementById("idstatut").value = newStatut;
	        }
	        			
	        function deletedossier(){
	        	var bool = confirm("Vous êtes sur le point de supprimer le dossier, êtes vous sur ?");
	        	if(bool){
	        		document.location.href="./handler/delete_treatment.php";
	        	}
	        }
	
			function checkFields(){
				 var listValueEmpty = ["date","nom", "prenom", "profession", "adresse1", "adresse3", "adresse4", "fumeur"];
				 var listValueEmptyEmprunt = ["montant", "taux",  "quotas", "duree"];
				 var listValueNumeric = ["montant", "quotas", "duree"];
				 var listValueNumeric2 = ["taux"];
				 var listValuePt = ["taux",  "quotas"];
				 var nbEmprunt = $('#nbEmprunt').val();
				 
				 var isgood = checkFieldsEmpty(listValueEmpty);
				
				 if(!isgood) return;

				 for(var i = 1; i <= nbEmprunt; i++)
				 {
					 var isgood = checkFieldsEmptyIndex(listValueEmptyEmprunt, i);
					 if(!isgood) return;
					isgood = checkFieldsNumericIndex(listValueNumeric, i);
					if(!isgood) return;
					isgood = checkFieldsNumericNotNullIndex(listValueNumeric2, i);
					if(!isgood) return;

					 isgood = checkPourcentageIndex(listValuePt, i);
					 if(!isgood)return;
					 
				 }

				
				 isgood = checkDate();
				
				 if(!isgood)return;
				 	
				 document.forms["dossier"].submit();

			}
	
	        
	        function checkDate(){
	        	var date = document.getElementById("date_naissance");
	        	var ok = true;
	        	var array = date.value.split("-");
	        	var year = array[2];
	        	var month = array[1];
	        	var day = array[0];
	
	        	ok = verifDate(parseInt(year,10),parseInt(month,10), parseInt(day,10));
	        	if(!ok){
	        		date.style.border = 'red 2px solid';
	        		date.style.backgroundColor = '#FDF1B8';
	        		alert("la date de naissance n'est pas valide");
	        	}else{
	        		date.style.border = '';
	        		date.style.backgroundColor = '';
	        	}
	        	return ok;
	        }
	
	        function verifDate(a,m,j){ 
	        	 m-=1;
	        	 d=new Date(a,m,j);
	        	 return (d.getFullYear()!=a || d.getMonth()!=m) ? false : true;
	        }
	
	        function updateCompta() {
	        	var primeAssurance = document.getElementById("prime_assurance");
	        	var tauxCommission = document.getElementById("taux_commission");
	        	var commissionBanque = document.getElementById("commission_banque");
	        	var commissionCourtier = document.getElementById("commission_courtier");
	        	if(primeAssurance.value > 0){
	        		commissionBanque.value = primeAssurance.value * 0.08;
	        		if(tauxCommission.value > 0){
	            		commissionCourtier.value = primeAssurance.value * tauxCommission.value;
	            	}
	        	}  	
	        }

			function addEmprunt(nbEmprunt){
				$("#nbEmprunt").val(nbEmprunt);
	        	$("#emprunt"+nbEmprunt).load('emprunttoinclude.php?nbEmprunt='+nbEmprunt); 
	        }

			function removeEmprunt(nbEmprunt){
				$("#nbEmprunt").val(nbEmprunt - 1);
				$("#emprunt"+(nbEmprunt)).load('emprunttoinclude.php?nbEmprunt='+(nbEmprunt-1)+" #emprunt"+(nbEmprunt)); 
	        }
        </script>
    </head>
    <!-- BODY -->
    <body>
    	<!-- HEADER -->
        <?php require_once'./include/header.php'; ?>
        <!-- MAIN -->
		<div id="main">
			<form id='dossier' action='./handler/modif_treatment.php?id=<?php echo $_GET['id']; ?>' method='post' accept-charset='UTF-8'>
				<?PHP if(isset($_GET["updated"])){ ?>
					<div class='notify'><span>&nbsp;Votre modification a &eacute;t&eacute; bien enregistr&eacute;e !&nbsp;</span></div>
				<?PHP } else { ?>
					<div class='notify'></div>
				<?PHP } ?>
				<fieldset id='fieldset_main'>
					<legend>DOSSIER : <?php echo $dossier->nom." ".$dossier->prenom; ?></legend>
					<input type='hidden' name='idstatut' id='idstatut' value='<?php echo $dossier->statut; ?>'/>
					<!-- Suivi Avancement -->
					<div id='dossier_status' style="position:relative">		
					<?php 
						$tab = array("<br>Demande<br>Emise","<br>Attente<br>Client","<br>Analyse<br>Assurance","<br>Complément<br>Médical","<br>Acceptation<br>Client","<br>Contrat<br>Emis","<br>Demande<br>Résiliation","<br>Contrat<br>Résilié");
						$val = 0;
						$leftvalue = 0; 
									
						foreach($tab as $value){
							if($_SESSION['user'] == 'admin'){
								if($val == $statut) {
										if($val >= 6) {
					?>
						<div onclick="javascript:changeStatut(<?php echo $val; ?>)" id="statut<?php echo $val; ?>" style="position:absolute;left:<?php echo $leftvalue; ?>em;background-image: url(ressources/statut_current_resiliation.png); height: 93px; width: 122px;"><p class='status' style="padding-left:10px"><?php echo $value; ?></p><div style="position:absolute;left:1.5em"><?php echo $dossier->date_changement_statut; ?></div></div>
						<?php		} else { ?>
						<div onclick="javascript:changeStatut(<?php echo $val; ?>)" id="statut<?php echo $val; ?>" style="position:absolute;left:<?php echo $leftvalue; ?>em;background-image: url(ressources/statut_current.png); height: 93px; width: 122px;"><p class='status' style="padding-left:10px"><?php echo $value; ?></p><div style="position:absolute;left:1.5em"><?php echo $dossier->date_changement_statut; ?></div></div>
					<?php		} ?>
					<?php		} else { ?>
						<div onclick="javascript:changeStatut(<?php echo $val; ?>)" id="statut<?php echo $val; ?>" style="position:absolute;left:<?php echo $leftvalue; ?>em;background-image: url(ressources/statut.png); height: 93px; width: 122px;"><p class='status' style="padding-left:10px"><?php echo $value; ?></p></div>
					<?php 		}
							} else {
								if($val == $statut) {
									if($val >= 6) {?>
										<div id="statut<?php echo $val; ?>" style="position:absolute;left:<?php echo $leftvalue; ?>em;background-image: url(ressources/statut_current_resiliation.png); height: 93px; width: 122px;"><p style="padding-left:10px"><?php echo $value; ?></p><div style="position:absolute;left:1.5em"><?php echo $dossier->date_changement_statut; ?></div></div>
								<?php		} else { ?>
										<div id="statut<?php echo $val; ?>" style="position:absolute;left:<?php echo $leftvalue; ?>em;background-image: url(ressources/statut_current.png); height: 93px; width: 122px;"><p style="padding-left:10px"><?php echo $value; ?></p><div style="position:absolute;left:1.5em"><?php echo $dossier->date_changement_statut; ?></div></div>
					<?php 		} 
								}else{?>
						<div id="statut<?php echo $val; ?>" style="position:absolute;left:<?php echo $leftvalue; ?>em;background-image: url(ressources/statut.png); height: 93px; width: 122px;"><p style="padding-left:10px"><?php echo $value; ?></p></div>
					<?php 		}
							}
							$leftvalue = $leftvalue+8;
							$val = $val + 1;
						}
					?>
 					</div>
					<!-- DOSSIER -->
					<fieldset class='fieldset_section'>
						<legend>Informations client</legend>
						<table>                         
							<tr>
								<td class='label'><label for='date' >Date*</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='date' id='date' value='<?php echo $dossier->date; ?>' maxlength="10" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='type_client' >Type de client</label></td>
								<td class='input'>
									<?php if($readOnlyMode == null){ ?>
									<select class='fill' name='type_client' id='type_client'>
										<option value='null' <?php if($dossier->type_client == "null") echo $selectedItem; ?> ></option>
										<option value='Particulier' <?php if($dossier->type_client == "Particulier") echo $selectedItem; ?> >Particulier</option>
										<option value='Professionnel' <?php if($dossier->type_client == "Professionnel") echo $selectedItem; ?> >Professionnel</option>
									</select>
									<?php } else { $typeClient = $dossier->type_client == "null" ? "" : $dossier->type_client; ?>
										<input <?php echo $readOnlyMode; ?> type='text' name='type_client' id='type_client' value='<?php echo $typeClient; ?>' maxlength="50" />
									<?php } ?>		
								</td>
							</tr>
							<tr>			
								<td class='label'><label for='societe' >Soci&eacute;t&eacute;</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='societe' id='societe' value='<?php echo $dossier->societe; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='numero_compte_client' >Num&eacute;ro de compte</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='numero_compte_client' id='numero_compte_client' value='<?php echo $dossier->numero_compte_client; ?>' maxlength="50" /></td>			
							</tr>		
							<tr>
								<td class='label'><label for='nom' >Nom*</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='nom' id='nom' value='<?php echo $dossier->nom; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='prenom' >Pr&eacute;nom*</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='prenom' id='prenom' value='<?php echo $dossier->prenom; ?>' maxlength="50" /></td>			
							</tr>
							<tr>
								<td class='label'><label for='profession' >Profession*</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='profession' id='profession' value='<?php echo $dossier->profession; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='date_naissance' >Date de naissance*</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?>  type='text' name='date_naissance' id='date_naissance' value='<?php echo $dossier->date_naissance; ?>' size="25" maxlength="10" /></td>
							</tr>
							<tr>
								<td class='label'><label for='email' >Email</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='email' id='email' value='<?php echo $dossier->email; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='tel_domicile' >Tel domicile</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='tel_domicile' id='tel_domicile' value='<?php echo $dossier->tel_domicile; ?>' maxlength="50" /></td>
							</tr>
							<tr>
								<td class='label'><label for='adresse1' >Adresse/Rue*</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='adresse1' id='adresse1' value='<?php echo $adresse1; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='tel_portable' >Tel portable</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='tel_portable' id='tel_portable' value='<?php echo $dossier->tel_portable; ?>' maxlength="50" /></td>
							</tr>
							<tr>
								<td class='label'><label for='adresse2' >Adresse/Compl&eacute;ment</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='adresse2' id='adresse2' value='<?php echo $adresse2; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='cadre' >Cadre</label></td>
								<td class='input'>
								<?php if($readOnlyMode == null){ ?>
									<select name='cadre' id='cadre'>
										<option value='0' <?php if($dossier->cadre == "Non") echo $selectedItem; ?> >Non</option>
										<option value='1' <?php if($dossier->cadre == "Oui") echo $selectedItem; ?> >Oui</option>
									</select>
									<?php } else { ?>
										<input <?php echo $readOnlyMode; ?> type='text' name='cadre' id='cadre' value='<?php echo $dossier->cadre; ?>' maxlength="50" />
									<?php } ?>		
								</td>
							</tr>
							<tr>
								<td class='label'><label for='adresse3&4' >CP - Ville*</label></td>
								<td class='input'>
									<input <?php echo $readOnlyMode; ?> type='text' class='cp' name='adresse3' id='adresse3' value='<?php echo $adresse3; ?>' maxlength="5" />&nbsp;<input <?php echo $readOnlyMode; ?> type='text' class='ville' name='adresse4' id='adresse4' value='<?php echo $adresse4; ?>' maxlength="30" />
								</td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='fumeur' >Fumeur*</label></td>
								<td class='input'>
								<?php if($readOnlyMode == null){ ?>
									<select name='fumeur' id='fumeur'>
										<option value='0' <?php if($dossier->fumeur == "Non") echo $selectedItem; ?> >Non</option>
										<option value='1' <?php if($dossier->fumeur == "Oui") echo $selectedItem; ?> >Oui</option>
									</select>
									<?php } else { ?>
										<input <?php echo $readOnlyMode; ?> type='text' name='fumeur' id='fumeur' value='<?php echo $dossier->fumeur; ?>' maxlength="50" />
									<?php } ?>		
								</td>
							</tr>
						</table>
					</fieldset>
					
					<?php 
					$list_emprunt = Emprunt::getListEmpruntByDossier($dossier->id);
					$nbEmprunt = count($list_emprunt);?>
					<input type='hidden' id='nbEmprunt' name='nbEmprunt' value='<?php echo $nbEmprunt?>'/> 
					<?php 
					for($i = 0; $i < $nbEmprunt; $i = $i +  1) {
					$emprunt = $list_emprunt[$i];?>
					
                  <div id="emprunt<?php  echo ($i + 1) ?>">
					<input type='hidden' name='id<?php echo ($i + 1) ?>' id='id<?php echo ($i + 1) ?>' value='<?php echo $emprunt->id; ?>' maxlength="50" />
					<fieldset class='fieldset_section'>
						<legend>Objet du financement <?php  echo ($i + 1) ?></legend>
						<table>
							<tr>
								<td class='label'><label for='montant' >Montant (€)*</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='montant<?php echo ($i + 1) ?>' id='montant<?php echo ($i + 1) ?>' value='<?php echo $emprunt->montant; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='taux' >Taux (%)*</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='taux<?php echo ($i + 1) ?>' id='taux<?php echo ($i + 1) ?>' value='<?php echo $emprunt->taux; ?>' maxlength="50" /></td>
							</tr>
							<tr>
								<td class='label'><label for='duree' >Durée (mois)*</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='duree<?php echo ($i + 1) ?>' id='duree<?php echo ($i + 1) ?>' value='<?php echo $emprunt->duree; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='quotas' >Quotit&eacute; &agrave; assurer (%)*</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='quotas<?php echo ($i + 1) ?>' id='quotas<?php echo ($i + 1) ?>' value='<?php echo $emprunt->quotas; ?>' maxlength="50" /></td>
							</tr>
							<tr>
								<td class='label'><label for='contrat_differe' >Contrat diff&eacute;r&eacute; (mois)</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='contrat_differe<?php echo ($i + 1) ?>' id='contrat_differe<?php echo ($i + 1) ?>' value='<?php echo $emprunt->contrat_differe; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='date_signature_prevu' >Date Signature</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='date_signature_prevu<?php echo ($i + 1) ?>' id='date_signature_prevu<?php echo ($i + 1) ?>' value='<?php echo $emprunt->date_signature_prevu; ?>' maxlength="10" /></td>
							</tr>							
							<tr>
								<td class='label'><label for='type_pret' >Type de pr&ecirc;t</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='type_pret<?php echo ($i + 1) ?>' id='type_pret<?php echo ($i + 1) ?>' value='<?php echo $emprunt->type_pret; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='numero_pret' >Num&eacute;ro du pr&ecirc;t</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='numero_pret<?php echo ($i + 1) ?>' id='numero_pret<?php echo ($i + 1) ?>' value='<?php echo $emprunt->numero_pret; ?>' maxlength="10" /></td>
							</tr>
							<tr>
								<td class='label'><label for='remarques' >Remarques</label></td>
								<td class='input'><textarea <?php echo $readOnlyMode; ?> rows="2" name='remarques<?php echo ($i + 1) ?>' id='remarques<?php echo ($i + 1) ?>'><?php echo $emprunt->remarques; ?></textarea></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='couvertures' >Couvertures*</label></td>						
								<td class='input'>
									<input <?php if($readOnlyMode != null){echo 'disabled="disabled"';} ?> type='checkbox' name='deces<?php echo ($i + 1) ?>' id='deces<?php echo ($i + 1) ?>' <?php if(strpos($emprunt->couvertures, "Deces")!==false){echo("checked='checked'");} ?> /><label for='deces' >D&eacute;c&egrave;s</label>
									&nbsp;&nbsp;<input <?php if($readOnlyMode != null){echo 'disabled="disabled"';} ?> type='checkbox' name='chomage<?php echo ($i + 1) ?>' id='chomage<?php echo ($i + 1) ?>' <?php if(strpos($emprunt->couvertures, "Chomage")!==false){echo("checked='checked'");} ?> onclick='javascript:manageCouverture()' /><label for='chomage' >Chomage</label>
									<br/><input <?php if($readOnlyMode != null){echo 'disabled="disabled"';} ?> type='checkbox' name='PTIA<?php echo $nbEmprunt ?>' id='PTIA<?php echo ($i + 1) ?>' <?php if(strpos($emprunt->couvertures, "PTIA")!==false){echo("checked='checked'");} ?> /><label for='PTIA' >PTIA</label>
									&nbsp;&nbsp;&nbsp;&nbsp;<input <?php if($readOnlyMode != null){echo 'disabled="disabled"';} ?> type='checkbox' name='ITT<?php echo ($i + 1) ?>' id='ITT<?php echo ($i + 1) ?>' <?php if(strpos($emprunt->couvertures, "ITT")!==false){echo("checked='checked'");} ?>/><label for='ITT' >ITT</label>									
								</td>	
							</tr>
						</table>
					<script type="text/javascript">
						new datepickr('date_signature_prevu<?php  echo ($i + 1) ?>', { 'dateFormat': 'd-m-Y', });			
					</script>
					</fieldset>
					
					<?php }?>
				<div id="emprunt<?php echo $nbEmprunt + 1 ?>">
					<div>
						<table align="center">
							<tr>
								<?php if($nbEmprunt > 1) {?>
								<td><input type='button'
									onclick="javascript:removeEmprunt(<?php  echo $nbEmprunt?>)"
									value='Supprimer' /></td>
								<?php }?>
								<td><input type='button'
									onclick="javascript:addEmprunt(<?php  echo $nbEmprunt + 1 ?>)"
									value='Ajouter' /></td>

							</tr>
						</table>
					</div>
				</div>
				</div>
				
				<fieldset class='fieldset_section'>
						<legend>Informations Emetteur</legend>
						<table>
							<tr>
								<td class='label'><label for='nom_emetteur' >Nom du salari&eacute;</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='nom_emetteur' id='nom_emetteur' value='<?php echo $dossier->nom_emetteur; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='prenom_emetteur' >Pr&eacute;nom du salari&eacute;</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='prenom_emetteur' id='prenom_emetteur' value='<?php echo $dossier->prenom_emetteur; ?>' maxlength="50" /></td>
							</tr>
							<tr>
								<td class='label'><label for='numero_matricule_emetteur' >Numero du matricule</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='numero_matricule_emetteur' id='numero_matricule_emetteur' value='<?php echo $dossier->numero_matricule_emetteur; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='numero_tel_emetteur' >Num&eacute;ro de Tel.</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='numero_tel_emetteur' id='numero_tel_emetteur' value='<?php echo $dossier->numero_tel_emetteur; ?>' maxlength="50" /></td>
							</tr>
							<tr>
								<td class='label'><label for='agence_service_emetteur' >Agence / Service</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='agence_service_emetteur' id='agence_service_emetteur' value='<?php echo $dossier->agence_service_emetteur; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='copie_emetteur' >Disribuer une copie &agrave;</label></td>
								<td class='input'><input <?php echo $readOnlyMode; ?> type='text' name='copie_emetteur' id='copie_emetteur' value='<?php echo $dossier->copie_emetteur; ?>' maxlength="50" /></td>
							</tr>	
						</table>
					</fieldset>					
					<!-- COMPTABILITE -->
					<?php if($_SESSION['user'] == 'admin') { ?>
						<?php
						
						$list_emprunt = Emprunt::getListEmpruntByDossier($dossier->id);
						$nbEmprunt = count($list_emprunt);
						for($i = 0; $i < $nbEmprunt; $i = $i +  1) {
							$emprunt = $list_emprunt[$i];
							$compta = Comptabilite::getComptaByEmprunt($emprunt->id);
						?>
					<fieldset class='fieldset_section'>
						<legend>Comptabilit&eacute;</legend>
						<table>                         
							<tr>
								<td class='label'><label>Nom</label></td>
								<td class='input'><input disabled="disabled" type='text' value='<?php echo $dossier->nom; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label>Pr&eacute;nom</label></td>
								<td class='input'><input disabled="disabled" type='text' value='<?php echo $dossier->prenom; ?>' maxlength="50" /></td>			
							</tr>
							<tr>
								<td class='label'><label>Banque</label></td>
								<td class='input'><input disabled="disabled" type='text' value='<?php echo $banque->nom; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label>Montant (€)</label></td>
								<td class='input'><input disabled="disabled" type='text' value='<?php  echo $emprunt->montant; ?>' maxlength="50" /></td>			
							</tr>
							<tr>
								<td class='label'><label for='date_debut' >Date d&eacute;but</label></td>
								<td class='input'><input type='text' name='date_debut<?php echo ($i + 1) ?>' id='date_debut<?php echo ($i + 1) ?>' value='<?php echo $compta->date_debut; ?>' maxlength="10" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='date_fin' >Date fin</label></td>
								<td class='input'><input type='text' name='date_fin<?php echo ($i + 1) ?>' id='date_fin<?php echo ($i + 1) ?>' value='<?php echo $compta->date_fin; ?>' maxlength="10" /></td>
							</tr>
							<tr>
								<td class='label'><label for='compagnie' >Compagnie</label></td>
								<td class='input'>
									<select class='fill' name='compagnie<?php echo ($i + 1) ?>' id='compagnie<?php echo ($i + 1) ?>'>
										<option value='null' <?php if($compta->compagnie == "null") echo $selectedItem; ?> ></option>
										<option value='GENERALI' <?php if($compta->compagnie == "GENERALI") echo $selectedItem; ?> >GENERALI</option>
										<option value='APREP' <?php if($compta->compagnie == "APREP") echo $selectedItem; ?> >APREP</option>
										<option value='AXA' <?php if($compta->compagnie == "AXA") echo $selectedItem; ?> >AXA</option>
										<option value='ASSUREA' <?php if($compta->compagnie == "ASSUREA") echo $selectedItem; ?> >ASSUREA</option>
										<option value='AUTRE' <?php if($compta->compagnie == "AUTRE") echo $selectedItem; ?> >Autre...</option>
									</select>
								</td>
								<td class='separator'><!-- SEPARETOR --></td>	
								<td class='label'><label for='numero_contrat' >Num&eacute;ro de contrat</label></td>
								<td class='input'><input type='text' name='numero_contrat<?php echo ($i + 1) ?>' id='numero_contrat<?php echo ($i + 1) ?>' value='<?php echo $compta->numero_contrat; ?>' maxlength="50" /></td>									
							</tr>
							<tr>
								<td class='label'><label for='prime_assurance' >Prime assurance</label></td>
								<td class='input'><input type='text' name='prime_assurance<?php echo ($i + 1) ?>' id='prime_assurance<?php echo ($i + 1) ?>' value='<?php echo $compta->prime_assurance; ?>' maxlength="50" onchange="javascript:updateCompta()"/></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='taux_commission' >Taux de commission</label></td>
								<td class='input'><input type='text' name='taux_commission<?php echo ($i + 1) ?>' id='taux_commission<?php echo ($i + 1) ?>' value='<?php echo $compta->taux_commission; ?>' maxlength="50" onchange="javascript:updateCompta()"/></td>
							</tr>
							<tr>
								
								<td class='label'><label for='commission_banque' >Commission banque</label></td>
								<td class='input'><input type='text' name='commission_banque<?php echo ($i + 1) ?>' id='commission_banque<?php echo ($i + 1) ?>' value='<?php echo $compta->commission_banque; ?>' maxlength="50" /></td>
								<td class='separator'><!-- SEPARETOR --></td>
								<td class='label'><label for='commission_courtier' >Commission courtier</label></td>
								<td class='input'><input type='text' name='commission_courtier<?php echo ($i + 1) ?>' id='commission_courtier<?php echo ($i + 1) ?>' value='<?php echo $compta->commission_courtier; ?>' maxlength="50" /></td>
							</tr>
						</table>
					</fieldset>
					<script>	
						new datepickr('date_debut<?php  echo ($i + 1) ?>', {
							'dateFormat': 'd-m-Y',
						});
		
						new datepickr('date_fin<?php  echo ($i + 1) ?>', {
							'dateFormat': 'd-m-Y',
						});	
					</script>
					<?php } ?>
					<?php } ?>
					<div class='message' >* champs obligatoires</div>
					<div><?php if($readOnlyMode == null){ ?>
						<input type='button' name='Submit' onclick='javascript:checkFields()' value='Sauvegarder' />
						&nbsp;&nbsp;&nbsp;<input type="button" name="deleteBtn" value="Supprimer" onclick="javascript:deletedossier()" />
					<?php } ?></div>
				</fieldset>
			</form>
			<?php if($readOnlyMode == null){ ?>
			<script type="text/javascript">
                new datepickr('date', {
					'dateFormat': 'd-m-Y',
				});
							
			</script>
			<?php } ?>
		</div>
		<!-- FOOTER -->
        <?php require_once'./include/footer.php'; ?>
	</body>
</html>
